{extend name="base"/}
{block name="css"}
<link rel="stylesheet" href="__MOBILE__/css/seller.css"/>
<style>
    .submit #submit{width: 85%;margin: .2rem auto;background: #FF604C;border: none;outline: none;padding: .2rem;color: #fff;display: block;border-radius: .5rem;}
    .s_info .item{margin-bottom:0;line-height: .7rem;color:#FF604C;border-top: .04rem solid #f5f5f5;}
    .s_info .intro{margin: .2rem 0;}
    .s_info .up{margin-bottom: .2rem;}
    .s_info .jigou{margin-bottom: .0;background: #fff;padding:0 .1rem;}
    .layui-form-item{margin-bottom: .0;background: #fff;padding:0 .1rem .2rem;}
    .pic-more li{margin-bottom: .1rem;}
    .s_info .tit i{font-size: .46rem;vertical-align: middle;}
    .layui-btn-primary:hover{border-color: #ff992e;}
    .w_xiangqingdizi{width: 100%;}
    .w_xiangqingdizi .con{width: 70%;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;}
    .s_info .item .con option{background-color: #fff;color: #000;}
    .head {position: fixed;top: 0;left: 0;width: 100%;height: 1rem;background-color: #fff;}
    .head_left {float: left;width: 20%;height: 1rem;}
    .head_left a {display: block;width: 100%;height: 100%;}
    .head_con {float: left;width: 60%;text-align: center;line-height: 1rem;font-size: .34rem;}
    .big_width100{margin-top: 1rem;}
    .shopbg{background:#fff;padding:.4rem;}
    .fo{background: url(../images/more2.png) center;}
    .txt{margin-left:.2rem;}
    .layui-input-block {
    margin-left: 0px;
    min-height: .72rem;
}
</style>
{/block}
{block name="content"}
<div class="head">
        <div class="head_left">
            <a href="javascript:history.go(-1)"><img src="/static/langjinmobile/images/true.png" alt=""></a>
        </div>
        <div class="head_con">上传产品</div>
    </div>
<div class="big_width100">
    <form  method="post" enctype="multipart/form-data" id="myForm" >
        <input type="hidden" name="id" value="{$goods.id}">
        <div class="s_info">
            <div class="item">
                <span class="txt">{:lang('商品名称')}</span>
                <input class="con" type="text" placeholder="{:lang('必填，输入商品的名称')}" name="name" value="{$goods.name}">
            </div>
            <div class="item">
                <span class="txt">{:lang('商品分类')}</span>
                    <select name="cat_id" id="category" class="con" style="background:#fff">   
                        <option value="0">{:lang('请选择商品分类')}</option>
                        {foreach name="categorys" item="category"}
                            <option value="{$category.cat_id}" {if $category.id == $goods.cat_id} selected="selected">{$category.cat_name}</option>
                        {/foreach}                      
                    </select>
            </div> 
            <div class="item">
                <span class="txt">{:lang('GMOB价格')}</span>
                <input class="con" type="number" placeholder="{:lang('必填，输入出售GMOB价格')}" name="wallet_num" value="{$goods.wallet_num}">
            </div>
            <div class="item">
                <span class="txt">{:lang('GMOD价格')}</span>
                <input class="con" type="number" placeholder="{:lang('必填，输入出售GMOD价格')}" name="integral_num" value="{$goods.integral_num}">
            </div>
            <div class="item">
                <span class="txt">{:lang('商品库存')}</span>
                <input class="con" type="number" placeholder="{:lang('必填，输入商品库存')}" name="amount" value="{$goods.amount}">
            </div>
            <div class="intro">
                <div class="item">
                    <!-- <img src="__MOBILE__/images/zc1-iocn.png" class="ico" alt=""> -->
                    <i class="iconfont icon-jieshao" style="color: #ff992e"></i>
                    <span class="txt">{:lang('描述')}</span>
                </div>
                <div class="txta">
                    <textarea cols="30" rows="10" placeholder="{:lang('请输入商家介绍')}" name="detail">{$goods.detail}</textarea>
                </div>
            </div>
                <div class="jigou img-box">
                    <div class="tit">
                        <!-- <img src="__MOBILE__/images/zc1-iocn.png" alt="" class="ico"> -->
                        <i class="iconfont icon-zhaopian" style="color: #f90"></i>
                        <span>{:lang('商品图')}{:lang('（图片上传大小为750*750）')}</span>
                        <span></span>
                    </div>
                </div>
    
            <div class="layui-form-item" id="pics">
                    <div class="layui-input-block" style="width: 100%;">
                        <div class="layui-upload">
                            <button type="button" class="layui-btn layui-btn-primary pull-left" id="slide-pc">{:lang('选择图片')}</button>
                            <div class="pic-more">
                            {if $goods.img1}
                                <ul class="pic-more-upload-list" id="slide-pc-priview">
                                    {foreach $goods.img1 as $key=>$val}
                                    <li class="item_img" style="float:left; margin-left:2%; width:31%;">
                                        <div class="operate"><i  class="close layui-icon"></i></div>
                                        <img src="{$val}" class="img" style="width:100%;"><input type="hidden" class="shopimg" name="pc_src[]" value="{$val}" />
                                    </li>
                                    {/foreach}
                                </ul>
                            {/if}
                            </div>
                        </div>
                    </div>
                </div>
            <div class="submit"><input type="button" lay-submit="" lay-filter="doAdd"  value="{:lang('确认上传')}" id="submit"></div>
        </div>
    </form>
</div>
{/block}
{block name="js"}
<script type="text/javascript" src="__ADMIN__/js/jquery.form.js"></script>
<script type="text/javascript" src="__ADMIN__/js/swiper.min.js"></script>
<script src="__ADMIN__/layui/layui.js"></script>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;    
        //执行一个laydate实例
        var time1=laydate.render({
            elem: '#fromTime' ,//指定元素
            type:'time',
            lang: 'en',
            value: '09:00:00'
        });
        var time2=laydate.render({
            elem:'#toTime',
            type:'time',
            lang: 'en',
            value: '20:00:00'

        })
    });

</script>
 <script>
        $(function () {
            $('.getimg').change(function () {
                var $imgShow = $(this).parents('.img-box').find('.show_img');
                var reader = new FileReader();
                reader.onload = function (e) {
                    $imgShow.attr("src", e.target.result)
                }
                reader.readAsDataURL(this.files[0]);
            });
        })
    </script>
    <script>
        layui.use('upload', function () {
            var $ = layui.jquery;
            var upload = layui.upload;
            upload.render({
                elem: '#slide-pc',
                field : 'pc_src',
                url: "{:url('/langjinmobile/Merchant/upload_img')}",
                size: 10000,
                type: "post",
                exts: 'jpg|png|jpeg|bmp|gif',
                multiple: true,
                number: 3,
                before: function (obj) {
                    layer.msg('图片上传中...', {
                        icon: 16,
                        shade: 0.01,
                        time: 0
                    })
                },
                done: function (res) {
                    layer.close(layer.msg()); //关闭上传提示窗口
                    if (res.status == 0) {
                        return layer.msg(res.message);
                    }
                    $('#slide-pc-priview').append(
                        '<li class="item_img" style="float:left; margin-left:2%; width:31%;"><div class="operate"><i  class="close layui-icon"></i></div><img src="' +
                        res.filepath +
                        '" class="img" style="width:100%;"><input type="hidden" class="shopimg" name="pc_src[]" value="' +
                        res.filepath + '" /></li>');
                }
            });
        });
        //点击多图上传的X,删除当前的图片    
        $("body").on("click", ".close", function () {
            $(this).closest("li").remove();
        });
        //多图上传点击<>左右移动图片
    /*    $("body").on("click", ".pic-more ul li .toleft", function () {
            var li_index = $(this).closest("li").index();
            if (li_index >= 1) {
                $(this).closest("li").insertBefore($(this).closest("ul").find("li").eq(Number(li_index) - 1));
            }
        });
        $("body").on("click", ".pic-more ul li .toright", function () {
            var li_index = $(this).closest("li").index();
            $(this).closest("li").insertAfter($(this).closest("ul").find("li").eq(Number(li_index) + 1));
        });*/
    </script>
    
    
    <script>
    layui.config({
        base: "/static/admin/js/"
    }).use(['form', 'layer', 'jquery', 'layedit', 'upload'], function () {
        var form = layui.form,
                layer = parent.layer === undefined ? layui.layer : parent.layer,
                upload = layui.upload,
                layedit = layui.layedit,
                $ = layui.jquery;
    
        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo1', {
            uploadImage: {
                url: '/shop/business/uploadImg/'
                ,type: 'post'
            }
        });

        form.on("submit(doAdd)", function (data) {    
            var formdom = $('#myForm')[0]
                ,formdata = new FormData(formdom);
            $.ajax({
                url: "{:url('/langjinmobile/Merchant/doEdit')}",
                type: 'POST',
                data: formdata,
                processData: false, // jQuery不要去处理发送的数据
                contentType: false, // jQuery不要去设置Content-Type请求头
                success: function(res) {
                    console.log(res);
                    if(res.status==1){
                        layer.msg(res.msg, {
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            setTimeout(window.location.href=res.url, 3000);
                        });
                    }else{
                        top.layer.msg(res.msg);
                    }
                }
            });
            return false;
        })
    });
        </script>
{/block}